<?php
html::printPath(array('organization.form-title' => 'admin/organization/all', 'application.page-title-display' => ''));
$msg->printMessages();
?>

<ul class="commandList">
    <li class="editLi"><?php echo html::anchor('admin/organization/edit?id=' . $organization['id'], text::get('organization.editThis')) ?></li>
    <li class="deleteLi"><?php echo html::anchor('admin/organization/delete?id=' . $organization['id'], text::get('organization.deleteThis'), array('onclick'=>'return confirmDeletion()')) ?></li>
</ul>
<ul class="commandList">
    <li class="goCommand"><?php echo html::anchor('/auth/switchOrganization?id=' . $organization['id'], text::get('organization-manageThisOrganization')); ?></li>
</ul>

<?php
$fb = new FormBuilder('organization', $organization);
$fb->displayOnly();
$fb->display('name')->identifyingValue();
$fb->display('country_code')->value($organization['country']['name_native'] . ' (' . $organization['country']['code'] . ')');
$fb->display('street');
$fb->display('postal_code');
$fb->display('city');
$fb->display('telephone');
$fb->display('email');
$fb->yesNoBox('emails_enabled');
$fb->comboBox('preferred_language', form::languageOptions());
$fb->display('organizer_id')->value(format::personFullName($organization['organizer']))->moreInfoPopup('/admin/person/display?id=' . $organization['organizer_id']);
$fb->textarea('notes');
$fb->write();

function deleteColumnValueFunction($person, $textField, $organization) {
    return html::anchor('/admin/organization/removeRepresentative?id=' . $organization['id'] . '&person_id=' . $person['id'], 
            html::img('remove.png', array('title' => text::get('organization-removeRepresentative'))));
}

if (! request::is_ajax()) {
    echo '<h2>' . text::getEscaped('organization.representativesOfThisOrg') . '</h2>';
    
    $fb = new FormBuilder('person', $organization);
    $fb->setAction('/admin/organization/addRepresentative');
    // $fb->hidden('id');
    $fb->autocompleter('person_id', $addRepAcValues)->mustMatch()->labelKey('organization.addRepresentative');
    $fb->write();
    
    if ($representativeList) {
        $elb = new EntityListBuilder('person', $representativeList);
        $elb->setUuid($this->DISPLAY_REP_LIST_UUID);
        $elb->text('last_name')->openInPopup();
        $elb->text('first_name');
        $elb->date('birth_date');
        $elb->text('country_name')->labelKey('country_code');
        $elb->text('delete')->valueFunction('deleteColumnValueFunction', $organization)->labelKey('util.emptyString');
        $elb->write();
    }

    if ($memberList) {
        echo '<h2>' . text::getEscaped('organization.membersOfThisOrganization') . '</h2>';
        $elb = new EntityListBuilder('person', $memberList);
        $elb->setUuid($this->DISPLAY_PERSON_LIST_UUID);
        $elb->text('last_name')->openInPopup();
        $elb->text('first_name');
        $elb->date('birth_date');
        $elb->text('country_name')->labelKey('country_code');
        $elb->write();
    }
}
